unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, Series, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    Timer1: TTimer;
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Memo1: TMemo;
    GroupBox2: TGroupBox;
    StatusBar1: TStatusBar;
    Timer2: TTimer;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  syspower: TSystemPowerStatus;
  systime: TSystemTime;
  bmp_filename: String;
  i : Integer;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(i);
  GetSystemPowerStatus(syspower);
  Chart1.SeriesList[0].AddY(syspower.BatteryLifePercent, IntToStr(i*30));
  Memo1.Lines.Append(IntToStr(i*30)+','+intToStr(syspower.BatteryLifePercent));

  if CheckBox1.Checked = true then
    Chart1.SaveToBitmapFile('.\battery_record'+bmp_filename+'.bmp');

  if CheckBox2.Checked = true then
    Memo1.Lines.SaveToFile('./battery_record_'+bmp_filename+'.csv');

  if (CheckBox3.Checked = true) And (syspower.BatteryLifePercent = 100) then begin
    Timer1.Enabled := false;
    Statusbar1.Panels[0].Text := 'App Stoped with Full charged'
  end;

  if (CheckBox4.Checked = true) And (syspower.BatteryLifePercent <= 5) then begin
    Timer1.Enabled := false;
    Statusbar1.Panels[0].Text := 'App Stoped with lower power'
  end;

  

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  GetLocalTime( systime );
  i:=0;
  GetSystemPowerStatus(syspower);
  Chart1.SeriesList[0].AddY(syspower.BatteryLifePercent, IntToStr(i*30));
  Memo1.Lines.Clear;
  bmp_filename := IntToStr(systime.wYear)+'-'+IntToStr(systime.wMonth)+'-'+IntToStr(systime.wDay)+'_'+IntToStr(systime.wHour)+IntToStr(systime.wMinute)+IntToStr(systime.wSecond);
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  if (CheckBox3.Checked = False) And (CheckBox4.Checked = False) then begin
    Timer1.Enabled := true;
    Statusbar1.Panels[0].Text := 'App start'
  end;
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin
  if CheckBox3.Checked = True then
    CheckBox3.Checked := False;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  if CheckBox4.Checked = True then
    CheckBox4.Checked := False;
end;

end.
